package com.sise.thread.FutureModel;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * 作者：idea
 * 日期：2018/6/24
 * 描述：
 */
public class FutureTask implements Callable {


    @Override
    public Object call() throws Exception {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("this is "+Thread.currentThread().getName());
        return "true";
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        List<Future> futureList=new ArrayList<>();
        ExecutorService es= Executors.newCachedThreadPool();
        System.out.println("测试开始");
        for(int i=0;i<100;i++){
            futureList.add(es.submit(new FutureTask()));
        }
        for (Future future : futureList) {
            System.out.println(future.get());
        }
        System.out.println("测试结束");

    }
}
